package com.huobao.yunying.activitys_welcome;

import android.content.Intent;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;

import com.huobao.yunying.base.HuobaoBaseActivity;
import com.huobao.yunying.utils.Utils;
import com.huobao.zhangying.R;

import org.taptwo.android.widget.CircleFlowIndicator;
import org.taptwo.android.widget.ViewFlow;
import org.taptwo.android.widget.ViewFlow.ViewSwitchListener;
import org.xutils.view.annotation.ViewInject;

import java.util.ArrayList;
import java.util.List;

public class Act_welcome_page extends HuobaoBaseActivity {
	/**
	 * 轮播图相关
	 */
	@ViewInject(R.id.viewflow)
	private ViewFlow m_ViewFlow;
	@ViewInject(R.id.viewflowindic)
	private CircleFlowIndicator m_CircleFlowIndicator;
	private Image1Adapter imageadapter;
	private List<Integer> list = new ArrayList<Integer>();

	@ViewInject(R.id.btn_1)
	private Button btn;

	@Override
	protected int getContentView() {
		return R.layout.layout_welcome_page;
	}

	@Override
	protected boolean isCheckPermission() {
		return false;
	}

	@Override
	protected String getTitleText() {
		return null;
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		return false;
	}

	@Override
	protected void init() {
		list.add(R.mipmap.wel1);
		list.add(R.mipmap.wel2);
		list.add(R.mipmap.wel3);
		list.add(R.mipmap.wel4);
		mAbTitleBar.setVisibility(View.GONE);
		imageadapter = new Image1Adapter();
		m_ViewFlow.setAdapter(imageadapter);
		m_ViewFlow.setFlowIndicator(m_CircleFlowIndicator);
		m_ViewFlow.setSideBuffer(list.size());
		m_ViewFlow.setOnViewSwitchListener(new ViewSwitchListener() {
			
			@Override
			public void onSwitched(View view, int position) {
				if (position == 3) {
					btn.setVisibility(View.VISIBLE);
				} else {
					btn.setVisibility(View.GONE);
				}
			}
		});
	}

	public void onGoclick(View view) {
		Utils.setLunched(context);
		startActivity(new Intent(this, Act_WelCome.class));
		finish();
	}

	public class Image1Adapter extends BaseAdapter {

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return 4;
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return 0;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			if (convertView == null)
				convertView = LayoutInflater.from(context).inflate(R.layout.image_item, null);
			ImageView imageView = (ImageView) convertView.findViewById(R.id.imgView);
			imageView.setImageResource(list.get(position));
			return convertView;
		}

	}
}
